"""
@author: 江同学呀
@file: base_time_field.py
@date: 2023/8/22 19:45
@desc:
"""


import datetime
from abc import ABC
from typing import Type, Union, Dict

from espc.orm.model.base.base import _Base
from espc.orm.model.mapping.field.base_field.base_field import _BaseField


class _BaseTimeField(_BaseField, ABC):
    """
    时间类型字段基类
    """
    _type: Type = datetime.datetime

    def __init__(
            self, field_name: str = None, value: datetime.datetime = None, default: datetime.datetime = None,
            *args, **kwargs
    ):
        super(_BaseTimeField, self).__init__(field_name=field_name, value=value, default=default, *args, **kwargs)
        return

    def __get__(self, instance: _Base, owner: Type["_BaseTimeField"]
                ) -> Union["_BaseTimeField", datetime.datetime]:
        return super(_BaseTimeField, self).__get__(instance=instance, owner=owner)

    def __set__(self, instance, value: datetime.datetime):
        super(_BaseTimeField, self).__set__(instance=instance, value=value)
        return

    @property
    def value(self) -> datetime.datetime:
        return self._value

    @value.setter
    def value(self, value: datetime.datetime):
        self._value: datetime.datetime = value
        return

    def _build(self) -> Dict:
        raise NotImplementedError


